using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using EcsSiteDSTableAdapters;

namespace SiteECSWeb
{
    [DataObject]
    public class ExporterGuideBLL
    {
        private ExporterGuideTableAdapter _ExporterguidAdapter = null;
        protected ExporterGuideTableAdapter ExporterGuideAdapter
        {
            get
            {
                if (_ExporterguidAdapter == null)
                {
                    _ExporterguidAdapter = new ExporterGuideTableAdapter();
                }
                return _ExporterguidAdapter;
            }
        }


        #region SelectExporterguid
        public int GetTotalNumberOfExporterGuide()
        {
            Nullable<int> totalNull =
                (Nullable<int>)ExporterGuideAdapter.TotalNumberOfExporterGuide();
            return totalNull.GetValueOrDefault();
        }
        public int GetTotalNumberOfExporterGuide(string FilterStr)
        {
            if (string.IsNullOrEmpty(FilterStr))
            {
                return GetTotalNumberOfExporterGuide();
            }
            else
            {
                Nullable<int> totalNull = (Nullable<int>)ExporterGuideAdapter.
                TotalNumberOfExporterGuideByFilterExp(FilterStr);
                return totalNull.GetValueOrDefault();
            }
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public EcsSiteDS.ExporterGuideDataTable GetAllExporterguidData()
        {
            return ExporterGuideAdapter.GetExporterGuideRowRankData();
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.ExporterGuideDataTable
            GetExporterGuideByExpGuideID(int Exporterguidid)
        {
            return ExporterGuideAdapter.GetExporterGuideDataByExporterguidId(Exporterguidid);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.ExporterGuideDataTable
            GetExporterGuideByRowRank(int RowRank)
        {
            return ExporterGuideAdapter.GetExporterGuideDataByRowRank(RowRank);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.ExporterGuideDataTable
            GetExporterGuideByCuntryID(string CuntryID)
        {
            return ExporterGuideAdapter.GetExporterGuideDataByCuntryID(CuntryID);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.ExporterGuideDataTable
            GetExporterGuideByExpGuidNmArFrstLetter(string Exporterguid_nmar , int TopCount )
        {
            return ExporterGuideAdapter.
                GetExporterGuideDataByExpGuidNmArFrstLetter(Exporterguid_nmar,TopCount);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.ExporterGuideDataTable
            GetExporterGuideByCountryNmEn(string CountryNmen)
        {
            return ExporterGuideAdapter.GetExporterGuideDataByCuntryEn(CountryNmen);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.ExporterGuideDataTable GetExporterGuideAsGridPagesAndFilterExpression(int startRowIndex,
            int maximumRows, string sortExpression)
        {
            return ExporterGuideAdapter.
                GetExporterGuideDataByGridPages(startRowIndex, maximumRows, sortExpression);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.ExporterGuideDataTable
            GetExporterGuideAsGridPagesAndFilterExpression(int startRowIndex, int maximumRows,
            string FilterStr, string sortExpression)
        {
            if (string.IsNullOrEmpty(FilterStr))
            {
                return
                    GetExporterGuideAsGridPagesAndFilterExpression(startRowIndex, maximumRows, sortExpression);
            }
            else
            {
                return ExporterGuideAdapter.GetExporterGuideDataByGridPagesFilterExp
                    (startRowIndex, maximumRows, FilterStr, sortExpression);
            }
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public PagedDataSource GetFairsByCuntryEnAsPagedDataSource
            (string CuntryEn, int pageIndex, int pageSize)
        {
            EcsSiteDS.ExporterGuideDataTable exporterGuideTable = GetExporterGuideByCountryNmEn(CuntryEn);

            PagedDataSource pagedData = new PagedDataSource();
            pagedData.DataSource = exporterGuideTable.Rows;
            pagedData.AllowPaging = true;
            pagedData.CurrentPageIndex = pageIndex;
            pagedData.PageSize = pageSize;
            return pagedData;
        }


        #endregion


        #region InsertExporterguid
        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public int AddExporterguid(string Exporterguid_nmar, string Exporterguid_nmen, string Exporterguid_memo,
            DateTime Exporterguid_Date, int City_id, bool? Publishing, bool Formemberonly,
            string Exporterguid_filepath, string Exporterguid_path)
        {
            EcsSiteDS.ExporterGuideDataTable ExporterguidTable = new EcsSiteDS.ExporterGuideDataTable();
            EcsSiteDS.ExporterGuideRow ExporterguidRow = ExporterguidTable.NewExporterGuideRow();

            if (string.IsNullOrEmpty(Exporterguid_nmen)) ExporterguidRow.SetExporterguid_nmenNull(); else ExporterguidRow.Exporterguid_nmen = Exporterguid_nmen;
            //if (string.IsNullOrEmpty(Exporterguid_filepath )) ExporterguidRow.SetExporterguid_filepathNull(); else ExporterguidRow.Exporterguid_filepath = Exporterguid_filepath;
            if (Publishing == null) ExporterguidRow.SetPublishingNull(); else ExporterguidRow.Publishing = Publishing.Value;
            if (string.IsNullOrEmpty(Exporterguid_path)) ExporterguidRow.SetExporterguid_filepathNull(); else ExporterguidRow.Exporterguid_path = Exporterguid_path;
            if (string.IsNullOrEmpty(Exporterguid_memo)) ExporterguidRow.SetExporterguid_memoNull(); else ExporterguidRow.Exporterguid_memo = Exporterguid_memo;

            ExporterguidRow.Exporterguid_Date = Exporterguid_Date;
            ExporterguidRow.Exporterguid_nmar = Exporterguid_nmar;
            ExporterguidRow.Formemberonly = Formemberonly;
            ExporterguidRow.City_id = City_id;
            ExporterguidRow.Exporterguid_filepath = Exporterguid_filepath;
            ExporterguidTable.AddExporterGuideRow(ExporterguidRow);
            int rowsAffected = ExporterGuideAdapter.Update(ExporterguidTable);

            return (rowsAffected == 1) ? ExporterguidRow.Exporterguid_id : -1;
        }


        #endregion


        #region UpdateExporterguid
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public bool UpdateExporterguid(string Exporterguid_nmar, string Exporterguid_nmen, string Exporterguid_memo,
            DateTime Exporterguid_Date, int City_id, bool? Publishing, bool Formemberonly,
            string Exporterguid_filepath, string Exporterguid_path, int Exporterguid_id)
        {
            EcsSiteDS.ExporterGuideDataTable ExporterguidTable = ExporterGuideAdapter.
                GetExporterGuideDataByExporterguidId(Exporterguid_id);

            if (ExporterguidTable.Count == 0)
            {
                return false;
            }
            EcsSiteDS.ExporterGuideRow ExporterguidRow = ExporterguidTable[0];

            if (string.IsNullOrEmpty(Exporterguid_nmen)) ExporterguidRow.SetExporterguid_nmenNull(); else ExporterguidRow.Exporterguid_nmen = Exporterguid_nmen;
            //if (string.IsNullOrEmpty(Exporterguid_filepath )) ExporterguidRow.SetExporterguid_filepathNull(); else ExporterguidRow.Exporterguid_filepath = Exporterguid_filepath;
            if (Publishing == null) ExporterguidRow.SetPublishingNull(); else ExporterguidRow.Publishing = Publishing.Value;
            if (string.IsNullOrEmpty(Exporterguid_path)) ExporterguidRow.SetExporterguid_filepathNull(); else ExporterguidRow.Exporterguid_path = Exporterguid_path;
            if (string.IsNullOrEmpty(Exporterguid_memo)) ExporterguidRow.SetExporterguid_memoNull(); else ExporterguidRow.Exporterguid_memo = Exporterguid_memo;

            ExporterguidRow.Exporterguid_Date = Exporterguid_Date;
            ExporterguidRow.Exporterguid_nmar = Exporterguid_nmar;
            ExporterguidRow.Formemberonly = Formemberonly;
            ExporterguidRow.City_id = City_id;
            ExporterguidRow.Exporterguid_filepath = Exporterguid_filepath;

            int rowsAffected = ExporterGuideAdapter.Update(ExporterguidRow);

            return rowsAffected == 1;
        }

        #endregion



        #region DeleteExporterguid
        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public bool DeletExporterGuide(int Exporterguid_id)
        {
            EcsSiteDS.ExporterGuideDataTable ExporterguidTable = ExporterGuideAdapter.
               GetExporterGuideDataByExporterguidId(Exporterguid_id);

            if (ExporterguidTable.Count == 0)
            {
                return false;
            }
            
            EcsSiteDS.ExporterGuideRow ExporterguidRow = ExporterguidTable[0];
            if (!ExporterguidRow.IsExporterguid_pathNull())
            {
                System.IO.File.Delete(HttpContext.Current.Server.MapPath(Globals.Settings.UploadInfo.RootAttachFolder
                            + ExporterguidRow.Exporterguid_path));
            }
            if (!ExporterguidRow.IsExporterguid_filepathNull())
            {
                System.IO.File.Delete(HttpContext.Current.Server.MapPath(Globals.Settings.UploadInfo.RootAttachFolder
                            + ExporterguidRow.Exporterguid_filepath));
            }


            int rowsAffected = ExporterGuideAdapter.Delete(Exporterguid_id);
            return rowsAffected == 1;
            
        }
        #endregion
    }

}
